package com.yunji.product.service.impl;

import com.yunji.common.utils.bean.BeanUtils;
import com.yunji.product.dao.IProductUnitDao;
import com.yunji.product.domain.ProductUnitDO;
import com.yunji.product.params.UnitParam;
import com.yunji.product.service.IProductUnitService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * @Project: yunji-coffee
 * @Package: com.yunji.product.service.impl
 * @Title: ProductUnitServiceImpl
 * <p>
 * History:
 * Date                     Version     Author          Summary
 * ============================================================
 * 2024-08-13 16:37:50      V1.0        HuaAo       新建类
 */
@Service
public class ProductUnitServiceImpl implements IProductUnitService {

    @Resource
    IProductUnitDao productUnitDao;

    @Override
    public boolean create(ProductUnitDO productUnit) {
        return productUnitDao.save(productUnit);
    }

    @Override
    public List<ProductUnitDO> search(UnitParam param) {
        List<ProductUnitDO> list = productUnitDao.search(param);
        return BeanUtils.isNotNull(list) ? list : new ArrayList<>();
    }

    @Override
    public ProductUnitDO select(Long unitId) {
        return productUnitDao.getById(unitId);
    }

    @Override
    public boolean update(ProductUnitDO productUnit) {
        return productUnitDao.updateById(productUnit);
    }

    @Override
    public void delete(Long... ids) {
        productUnitDao.removeByIds(Arrays.asList(ids));
    }

    @Override
    public ProductUnitDO getCacheById(Long id) {
        return productUnitDao.getById(id);
    }
}